<?php
/**
 * TomatoCMS
 *
 * LICENSE
 *
 * This source file is subject to the GNU GENERAL PUBLIC LICENSE Version 2
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl-2.0.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@tomatocms.com so we can send you a copy immediately.
 *
 * @copyright    Copyright (c) 2009-2010 TIG Corporation (http://www.tig.vn)
 * @license        http://www.gnu.org/licenses/gpl-2.0.txt GNU GENERAL PUBLIC LICENSE Version 2
 * @version     $Id: add.phtml 3032 2010-05-25 08:00:42Z huuphuoc $
 */
?>
<?php
$this->headTitle($this->translator('enterprise_edit_account_payment_page_title'));
$this->headLink()
    ->appendStylesheet($this->APP_STATIC_SERVER . '/js/jquery.ui/themes/base/ui.all.css')
    ->appendStylesheet($this->APP_STATIC_SERVER . '/js/jquery.ui/themes/base/ui.datepicker.css');

$this->headScript()
    ->appendFile($this->APP_STATIC_SERVER . '/js/jquery.validate/jquery.validate.min.js')
    ->appendFile($this->APP_STATIC_SERVER . '/js/jquery.ui/ui.datepicker.js');
?>

<div class="grid_12 t_a_ui_breadcrumb">
    <span><a href="<?php echo $this->url(array(), 'enterprise_enterprise_list'); ?>"><?php echo $this->translator('enterprise_list_breadcump'); ?></a></span>
    <span><?php echo $this->translator('enterprise_edit_payment_infor_breadcump'); ?></span>
</div>

<div class="grid_12"><?php echo $this->flashMessenger(); ?></div>

<form method="post" action="<?php echo $this->url(array('enterprise_id' => $this->enterprise_id), 'enterprise_enterprise_payment_info'); ?>" id="editPaymentForm">
<div class="grid_12 t_a_bottom"><?php echo $this->translator('enterprise_edit_guide'); ?></div>

<div class="grid_12 t_a_bottom">
    <div class="prefix_1 suffix_1">
        <?php if(!$this->isAllowed):?>
            <?php echo $this->translator('enterprise_not_edit_basic_guide'); ?>
        <?php else:?>
        <div class="clearfix t_a_bottom">
            <label><?php echo $this->translator('enterprise_last_payment_date'); ?>:</label>
            <input type="text" id="last_payment_date" name="last_payment_date" style="width: 100px" value="<?php if (null != $this->payment && null != $this->payment->last_payment_date) : ?><?php echo date('d/m/Y',strtotime($this->payment->last_payment_date)); ?><?php endif; ?>" />
        </div>

        <hr/>

        <div class="clearfix t_a_bottom">
            <label><?php echo $this->translator('enterprise_last_payment_amount'); ?>:</label>
            <input type="text" id="last_payment_amount" name="last_payment_amount" style="width: 100px" value="<?php if (null != $this->payment && null != $this->payment->last_payment_amount) : ?><?php echo $this->payment->last_payment_amount; ?><?php endif; ?>" /> VND
        </div>

        <hr/>

        <div class="clearfix t_a_bottom">
            <label><?php echo $this->translator('enterprise_account_valid_until_date'); ?>:</label>
            <input type="text" id="account_valid_until_date" name="account_valid_until_date" style="width: 100px" value="<?php if (null != $this->payment && null != $this->payment->account_valid_until_date) : ?><?php echo date('d/m/Y',strtotime($this->payment->account_valid_until_date)); ?><?php endif; ?>" />
        </div>

        <hr/>

        <div class="clearfix t_a_bottom">
            <label>&nbsp;</label>
            <button type="submit"><span><?php echo $this->translator('enterprise_add_save_button'); ?></span></button>&nbsp;&nbsp;&nbsp;
            <button type="reset"><span><?php echo $this->translator('enterprise_reset_button'); ?></span></button>
        </div>
        <?php endif;?>
    </div>
</div>
</form>

<script type="text/javascript">

$(document).ready(function() {

    /**
    * Create datepicker instances
    */
    $('#last_payment_date').datepicker({ dateFormat: 'dd/mm/yy' });
    $('#account_valid_until_date').datepicker({ dateFormat: 'dd/mm/yy' });

    jQuery.validator.addMethod("greaterThanZero", function(value, element) {
        return this.optional(element) || (parseFloat(value) > 0);
        }, "* Amount must be greater than zero");

    $('#editPaymentForm').validate({
        rules: {
            last_payment_amount: {
                number: true,
                greaterThanZero: true
            }
        },
        messages: {
            last_payment_amount: {
                number: "<?php echo $this->translator('enterprise_last_payment_amount_invalid_number'); ?>",
                greaterThanZero: "<?php echo $this->translator('enterprise_last_payment_amount_invalid_number'); ?>"
            }
        }
    });
});
</script>
